package com.zhong.gang.app.utils;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import androidx.databinding.DataBindingUtil;
import com.zhong.gang.app.R;
import com.zhong.gang.app.api.Api;
import com.zhong.gang.app.databinding.ItemChailiaoBinding;
import com.zhong.gang.app.db.UserBean;
import com.zhong.gang.app.db.UserUtils;
import com.zhong.gang.applib.CheseListener;
import com.zhong.gang.applib.bean.MaterialBean;
import com.zhong.gang.applib.ui.chese.MaterialAct;
import com.zhong.gang.applib.ui.chese.MaterialTypeBean;

public class MaterialItemView extends FrameLayout implements CheseListener {
    private ItemChailiaoBinding binding;
    private MaterialTypeBean bean;
    private int steelMillId,type;
    private String[] strings = new String[]{"一","二","三","四","五","六","七","八","九","十","十一","十二","十三","十四","十五","十六","十七","十八","十九","二十"};

    public MaterialTypeBean getBean() {
        return bean;
    }


    public MaterialItemView(Context context,int number,int steelMillId,int type) {
        super(context);
        this.steelMillId = steelMillId;
        this.type = type;
        View view =LayoutInflater.from(getContext()).inflate(R.layout.item_chailiao,null);
        binding = DataBindingUtil.bind(view);
        if (number < strings.length)
            binding.typeName.setText("装车料型类型"+strings[number]);
        binding.setItem(this);
        this.addView(view);
    }

    public MaterialItemView(Context context,int number, MaterialBean bean) {
        super(context);
        View view =LayoutInflater.from(getContext()).inflate(R.layout.item_chailiao,null);
        binding = DataBindingUtil.bind(view);
        if (number < strings.length)
            binding.typeName.setText("装车料型类型"+strings[number]);
        binding.typeTv.setText(bean.getMaterialTypeName());
        binding.edt.setText(bean.getWeight()+"");
        binding.edt.setEnabled(false);
        binding.type.setEnabled(false);
        binding.setItem(this);
        this.addView(view);
    }

    /**
     * 点击事件
     * @param view
     */
    public void onViewClicked(View view){
        UserBean userBean = UserUtils.getIntent(getContext()).getUser();
        MaterialAct.openAct(getContext(), Api.materialTypeList,
                steelMillId+"",type+""
                ,userBean.isLogin(),userBean.getToken(),userBean.getId()+""
                ,UserUtils.getIntent(getContext()).getRoleId()+"",this);
    }

    public ItemChailiaoBinding getBinding(){
        return binding;
    }

    @Override
    public void onCheseBack(MaterialTypeBean bean) {
        this.bean = bean;
        binding.typeTv.setText(bean.getName());
    }
}
